home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 16 code / CollaboDraw / windowstuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-24  |  6.6 KB  |  339 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * Simple Sample PowerTalk Application Framework
  4.  *
  5.  * ©1991-1993 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * windowstuff.c -- window class instantiation/dispatching
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        08/23/93        1.0f1        update to final headers, fix comments
  14.  * SJF        04/21/93        1.0b2        update to b2
  15.  * SJF        03/01/93        1.0b1        added digital signatures
  16.  * SJF        02/09/93        1.0b1        update to b1
  17.  * SJF        10/13/92        1.0d4        update to a11
  18.  * SJF        09/09/92        1.0d3        update to a9
  19.  * SJF        05/07/92        1.0d2        update to a6
  20.  * SJF        11/06/91        1.0d1        initial coding
  21.  *
  22.  */
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27.  
  28. #ifndef __QUICKDRAW__
  29. #include <QuickDraw.h>
  30. #endif
  31.  
  32. #ifndef __WINDOWS__
  33. #include <Windows.h>
  34. #endif
  35.  
  36. #ifndef __MEMORY__
  37. #include <Memory.h>
  38. #endif
  39.  
  40. #ifndef __MENUS__
  41. #include <Menus.h>
  42. #endif
  43.  
  44. #ifndef __OCESTANDARDMAIL__
  45. #include <OCEStandardMail.h>
  46. #endif
  47.  
  48. #include "const.h"
  49. #include "mytypes.h"
  50. #include "globals.h"
  51. #include "utils.h"
  52.  
  53. #include "base.window.h"
  54. #include "draw.window.h"
  55. #include "draw.mailer.window.h"
  56.  
  57. #include "windowstuff.h"
  58.  
  59. /* gets info handle for a window */
  60.  
  61. WInfoHndl GetWindowInfo(WindowPtr window)
  62. {
  63.     WInfoHndl theInfo;
  64.     
  65.     if (window==nil)
  66.         return nil;
  67.         
  68.     theInfo = (WInfoHndl) GetWRefCon(window);
  69.     return theInfo;
  70. }
  71.  
  72.  
  73. /* sets info handle for a window */
  74.  
  75. void SetWindowInfo(WindowPtr window,WInfoHndl info)
  76. {
  77.     if (window==nil) {
  78.         DoError(kInternalError);
  79.         return;
  80.     }
  81.         
  82.     SetWRefCon (window,(long)info);
  83. }
  84.  
  85.  
  86. /* gets window kind of a given window */
  87.  
  88. WindowKind GetWindowKind(WindowPtr window)
  89. {
  90.     WindowKind wKind;
  91.     
  92.     if (window==nil) {
  93.         DoError(kInternalError);
  94.         return 0;
  95.     }
  96.     wKind = ((WindowPeek)window)->windowKind;
  97.     return wKind;
  98. }
  99.  
  100.  
  101. /* sets window kind of a given window */
  102.  
  103. void SetWindowKind(WindowPtr window,WindowKind wKind)
  104. {
  105.     if (window==nil) {
  106.         DoError(kInternalError);
  107.         return;
  108.     }
  109.  
  110.     ((WindowPeek)window)->windowKind = wKind;
  111. }
  112.  
  113.  
  114. /* checks to see if a window is of a certain type */
  115.  
  116. Boolean IsWindowType(WindowPtr window,WindowKind type)
  117. {
  118.     return (type == GetWindowKind(window));
  119. }
  120.  
  121.  
  122. /* returns true if it's a window created by the application */
  123.  
  124. Boolean IsAppWindow(WindowPtr window)
  125. {
  126.     WindowKind wKind;
  127.     
  128.     if (!window)
  129.         return false;
  130.     
  131.     wKind = GetWindowKind(window);
  132.     return (wKind >= userKind);
  133. }
  134.  
  135.  
  136. /* returns true if the window belongs to a DA */
  137.  
  138. Boolean IsDAWindow(WindowPtr window)
  139. {
  140.     return (GetWindowKind(window) < 0);
  141. }
  142.  
  143.  
  144. /* returns the _real_ frontwindow, not including the AOCE copy window */
  145.  
  146. WindowPtr MyFrontWindow(void)
  147. {
  148.     WindowPtr window;
  149.     
  150.     window = FrontWindow();
  151.     
  152.     if (gHasCopyWindow) {
  153.         window = (WindowPtr) (((WindowPeek)window)->nextWindow);
  154.     }
  155.     return window;
  156. }
  157.  
  158.  
  159. /* locks the data area of a window */
  160.  
  161. WInfoPtr BeginWindowAccess(WindowPtr theWindow,char *hState)
  162. {
  163.     WInfoHndl infoHndl;
  164.     
  165.     infoHndl = GetWindowInfo(theWindow);
  166.     *hState = HGetState((Handle) infoHndl);
  167.     MoveHHi((Handle) infoHndl);
  168.     HLock((Handle) infoHndl);
  169.     return *infoHndl;
  170. }
  171.  
  172.  
  173. /* unlocks the data area of a window */
  174.  
  175. void EndWindowAccess(WindowPtr theWindow,char hState)
  176. {
  177.     WInfoHndl infoHndl;
  178.     
  179.     infoHndl = GetWindowInfo(theWindow);
  180.     HSetState((Handle) infoHndl,hState);
  181. }
  182.  
  183.  
  184. /* makes a window of a given type and returns its window pointer */
  185.  
  186. WindowPtr MakeWindow(WindowKind windowClass,Rect *wRect,StringPtr title,Boolean visible)
  187. {
  188.     WindowPtr window,windowLook;
  189.     Rect theRect;
  190.     short expHeight,contHeight,mWidth;
  191.     OSErr err;
  192.     Point offsetWind;
  193.     GrafPtr savePort;
  194.     
  195.     if (wRect==nil)
  196.     {
  197.         if (gHasStandardMail) {
  198.             err = SMPGetDimensions(&mWidth,&contHeight,&expHeight);
  199.             if (err!=noErr)
  200.                 DoError(err);
  201.         }
  202.         else mWidth = 492;
  203.         SetRect(&theRect, 20, 50, 20 + mWidth, 340);
  204.         
  205.         GetPort(&savePort);
  206.         windowLook = MyFrontWindow();
  207.         while (windowLook) {
  208.             SetPt(&offsetWind,0,0);
  209.             SetPort(windowLook);
  210.             LocalToGlobal(&offsetWind);
  211.             if (theRect.top==offsetWind.v && theRect.left==offsetWind.h) {
  212.                 OffsetRect(&theRect,kWindowOffset,kWindowOffset);
  213.                 windowLook = MyFrontWindow();
  214.             }
  215.             else
  216.                 windowLook=(WindowPtr)((WindowPeek)windowLook)->nextWindow;
  217.         }
  218.         SetPort(savePort);
  219.             
  220.     } else
  221.         theRect = *wRect;
  222.         
  223.     switch (windowClass) {
  224.         case kBaseWindow:
  225.             window = BaseMakeWindow(&theRect,title,visible,zoomDocProc,true);
  226.             break;
  227.         case kDrawWindow:
  228.             window = DrawMakeWindow(&theRect,title,visible,zoomDocProc,true);
  229.             break;
  230.         case kDrawMailerWindow:
  231.             window = DMailerMakeWindow(&theRect,title,visible,zoomDocProc,true);
  232.             break;
  233.         default:
  234.             DoError(kInternalError);
  235.     }
  236.     
  237.     return window;
  238. }
  239.  
  240.  
  241. /* sends a message to a given window */
  242.  
  243. void *SendWindowMessage(WindowPtr window,short msg,void *data)
  244. {
  245.     WInfoHndl infoHndl;
  246.     char hState;
  247.     MsgProc callProc;
  248.     void *theMsg;
  249.     
  250.     if (!IsAppWindow(window))
  251.         return nil;
  252.     
  253.     infoHndl = GetWindowInfo(window);
  254.     hState = HGetState((Handle) infoHndl);
  255.     HLock((Handle) infoHndl);
  256.     
  257.     switch (msg) {
  258.         case kIdleMessage:
  259.             callProc = (**infoHndl).m_idle;
  260.             break;
  261.         case kFixCursorMessage:
  262.             callProc = (**infoHndl).m_fixCursor;
  263.             break;
  264.         case kActivateMessage:
  265.             callProc = (**infoHndl).m_activate;
  266.             break;
  267.         case kDeactivateMessage:
  268.             callProc = (**infoHndl).m_deactivate;
  269.             break;
  270.         case kUpdateMessage:
  271.             callProc = (**infoHndl).m_update;
  272.             break;
  273.         case kKeyMessage:
  274.             callProc = (**infoHndl).m_key;
  275.             break;
  276.         case kResizeMessage:
  277.             callProc = (**infoHndl).m_resize;
  278.             break;
  279.         case kClickMessage:
  280.             callProc = (**infoHndl).m_click;
  281.             break;
  282.         case kDestroyMessage:
  283.             callProc = (**infoHndl).m_destroy;
  284.             break;
  285.         case kUndoMessage:
  286.             callProc = (**infoHndl).m_undo;
  287.             break;
  288.         case kCutMessage:
  289.             callProc = (**infoHndl).m_cut;
  290.             break;
  291.         case kCopyMessage:
  292.             callProc = (**infoHndl).m_copy;
  293.             break;
  294.         case kPasteMessage:
  295.             callProc = (**infoHndl).m_paste;
  296.             break;
  297.         case kClearMessage:
  298.             callProc = (**infoHndl).m_clear;
  299.             break;
  300.         case kPrintMessage:
  301.             callProc = (**infoHndl).m_print;
  302.             break;
  303.         case kPageSetupMessage:
  304.             callProc = (**infoHndl).m_pageSetup;
  305.             break;
  306.         case kSaveMessage:
  307.             callProc = (**infoHndl).m_save;
  308.             break;
  309.         case kLoadMessage:
  310.             callProc = (**infoHndl).m_load;
  311.             break;
  312.         case kEventMessage:
  313.             callProc = (**infoHndl).m_event;
  314.             break;
  315.         case kHitControlMessage:
  316.             callProc = (**infoHndl).m_ctrlHit;
  317.             break;
  318.         case kSelectAllMessage:
  319.             callProc = (**infoHndl).m_selectAll;
  320.             break;
  321.         case kGroupMessage:
  322.             callProc = (**infoHndl).m_group;
  323.             break;
  324.         case kUnGroupMessage:
  325.             callProc = (**infoHndl).m_unGroup;
  326.             break;
  327.         default:
  328.             return nil;
  329.     }
  330.     
  331.     if (callProc)
  332.         theMsg = (*callProc)(window,*infoHndl,data);
  333.     
  334.     HSetState((Handle) infoHndl,hState);
  335.     return theMsg;
  336. }
  337.  
  338.  
  339.